# Create your views here.
from django.http import HttpResponse
from django.shortcuts import render

from apps.api.mapper.sql_connect import read_user_info


# 登录注册界面
def home(req):
    return render(req, 'login_register.html')


# 功能界面
def func(req):
    return render(req, 'detect_fuc.html')


# 用户管理界面
def user_backend(request):
    status = request.GET.get('status')
    if status == 0:
        return HttpResponse("用户无权访问后台数据管理界面。")
    else:
        user_Data = read_user_info()
        column_list = user_Data.columns.tolist()
        # 使用列表推导式将每一行记录转换为元组
        tuples = [tuple(row) for index, row in user_Data.iterrows()]
        response = {
            'column_list': column_list,
            'data': tuples
        }
        return render(request, 'backend.html', response)
